package com.itheima.employee.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.employee.mapper.PositiveMapper;
import com.itheima.employee.pojo.EmployeePositive;
import com.itheima.employee.service.PositiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @author qiankaofei
 * @version 1.0
 * @date 2020/11/16 10:45
 */
@Service
@Transactional
public class PositiveServiceImpl implements PositiveService {
    @Autowired
    private PositiveMapper positiveMapper;

    private static final Integer NOESTATUS=1;

    public EmployeePositive findById(String uid, Integer status) {
        QueryWrapper<EmployeePositive> wrapper=new QueryWrapper<EmployeePositive>();
        wrapper.eq("user_id",uid);
        EmployeePositive positive = positiveMapper.selectOne(wrapper);
        if(status!=null && positive!= null){
            if(positive.getEstatus()!=status){
                positive=null;
            }
        }
        return positive;
    }

    /**
     * 转正表单读取
     */
    public EmployeePositive findById(String uid) {
        QueryWrapper<EmployeePositive> wrapper=new QueryWrapper<EmployeePositive>();
        wrapper.eq("user_id",uid);
        return positiveMapper.selectOne(wrapper);
    }

    /***
     * 转正表单保存
     * @param positive
     * @return
     */
    public Integer save(EmployeePositive positive) {
        positive.setCreateTime(new Date());
        positive.setEstatus(NOESTATUS);
        return positiveMapper.insert(positive);
    }
}
